//
//  SGJNormalReportViewController.m
//  Sewage
//
//  Created by 优聚泰元 on 2017/6/8.
//  Copyright © 2017年 宗庆猛. All rights reserved.
//

#import "SGJNormalReportViewController.h"
#import "UIColor+sewageColor.h"

#import "SGJNetworkTools.h"

@interface SGJNormalReportViewController ()

@end

@implementation SGJNormalReportViewController



-(void)submit{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    
    NSMutableDictionary *contentDict = [NSMutableDictionary dictionary];
    contentDict[@"taskId"] = self.tempObject.sewageTask.id;
   // contentDict[@"id"] = taskExamineCell.poiModel.poiUserRecordId;
  //  contentDict[@"deviceItemId"] = taskExamineCell.poiModel.deviceId;;
   // contentDict[@"poiId"] = taskExamineCell.poiModel.poiCode;
    contentDict[@"remark"] = @"";
    contentDict[@"type"] = self.tempObject.sewageTask.type;
    //contentDict[@"userLng"] = taskExamineCell.poiModel.userLng;
   // contentDict[@"userLat"] = taskExamineCell.poiModel.userLat;
    
    params[@"content"] = contentDict;
    params[@"voiceRecord"] = @"";
    params[@"userId"] = [[NSUserDefaults standardUserDefaults] objectForKey:@"userId"];
    params[@"totalFile"] = nil;
    
    [[SGJNetworkTools sharedNetworkTool] routingInspectionWithUrlString:kRoutingInspectionUrl parameters:params method:@"POST" callBack:^(id responseObject) {
        NSLog(@"设备巡检%@",responseObject);
    }];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"报告";
    
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] initWithTitle:@"提交" style:UIBarButtonItemStyleDone target:self action:@selector(submit)];
    self.navigationItem.rightBarButtonItem = rightItem;
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, [UIScreen mainScreen].bounds.size.width - 20, 300)];
    topView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:topView];
    
    UILabel *lable = [[UILabel alloc] initWithFrame:CGRectMake(15, 8, 200, 14)];
    lable.text = @"拍照（必填）";
    lable.textColor = [UIColor colorFromHexString:@"#333333"];
    [topView addSubview:lable];
    
    UIButton *cameraButton = [UIButton buttonWithType:UIButtonTypeCustom];
    cameraButton.frame = CGRectMake(topView.frame.size.width - 30, 8, 19, 17);
    [cameraButton setImage:[UIImage imageNamed:@"拍照"] forState:UIControlStateNormal];
    [cameraButton addTarget:self action:@selector(takePicture) forControlEvents:UIControlEventTouchUpInside];
    [topView addSubview:cameraButton];
    
    UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(lable.frame)+ 8, topView.frame.size.width, 1)];
    lineView.backgroundColor = [UIColor lightGrayColor];
    [topView addSubview:lineView];
}

#pragma mark - 拍照

-(void)takePicture{
    UIImagePickerController *imagePictureCtr = [[UIImagePickerController alloc] init];
    imagePictureCtr.delegate = self;
    //  是否执行传入的来源类型
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        imagePictureCtr.sourceType = UIImagePickerControllerSourceTypeCamera;
    }else{
        imagePictureCtr.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    }
    
    //  判断是否支持前置设置头
    if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]) {
        NSLog(@"支持前置摄像头");
    }
    if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]) {
        NSLog(@"支持后置摄像头");
    }
    
    [self presentViewController:imagePictureCtr animated:YES completion:nil];
}

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    [picker dismissViewControllerAnimated:YES completion:nil];
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
    NSLog(@"%@",info);
    
    UIImage *image = info[UIImagePickerControllerOriginalImage];
    
    NSLog(@"image%@",image);
    
    //UIImage *scaleImage = [image scaleImageWithScaleWidth:200];
    
    //[self.pictureView addImageWithImage:scaleImage];
    
    [picker dismissViewControllerAnimated:YES completion:nil];
}

@end
